package org.ala.tiktools.sharddb.mybatis.pager.with_order;

import org.ala.tiktools.sharddb.mybatis.router.ShardInfo;

import java.util.Map;

/**
 * 每个分表 极值左边 的数量和 等于极值 的数量
 *
 * @author ala
 * @date 2025-03-09 16:35
 */
public class ShardPageExtremeDO {

    /**
     *  汇总的左边数量
     */
    protected int countLeft;
    /**
     *  汇总的等于数量
     */
    protected int countEq;
    /**
     *  汇总的左边和eq的数量
     */
    protected int countLeftEq;
    /**
     *  每个分库分表的数量
     */
    protected Map<ShardInfo, PageExtremeDO> shards;


    public static ShardPageExtremeDO build(Map<ShardInfo, PageExtremeDO> map) {
        ShardPageExtremeDO d = new ShardPageExtremeDO();
        map.forEach(((shardInfo, pageExtremeDO) -> {
            d.countEq += pageExtremeDO.countEq;
            d.countLeft += pageExtremeDO.countLeft;
        }));
        d.shards = map;
        d.countLeftEq = d.countLeft + d.countEq;
        return d;
    }

    public int getCountLeft() {
        return countLeft;
    }

    public void setCountLeft(int countLeft) {
        this.countLeft = countLeft;
    }

    public int getCountEq() {
        return countEq;
    }

    public void setCountEq(int countEq) {
        this.countEq = countEq;
    }

    public Map<ShardInfo, PageExtremeDO> getShards() {
        return shards;
    }

    public void setShards(Map<ShardInfo, PageExtremeDO> shards) {
        this.shards = shards;
    }

    public int getCountLeftEq() {
        return countLeftEq;
    }

    public void setCountLeftEq(int countLeftEq) {
        this.countLeftEq = countLeftEq;
    }

    /**
     *  分库分表
     */
    public static class PageExtremeDO {
        /**
         *  分库分表
         */
        protected ShardInfo shardInfo;
        /**
         *  极值左边的数量
         */
        int countLeft;
        /**
         *  等于极值的数量
         */
        int countEq;
        /**
         *  左边并且等于极值的数量
         */
        int countLeftEq;

        public static PageExtremeDO build(ShardInfo shardInfo, int countLeft, int countEq) {
            PageExtremeDO d = new PageExtremeDO();
            d.shardInfo = shardInfo;
            d.countLeft = countLeft;
            d.countEq = countEq;
            d.countLeftEq = countLeft + countEq;
            return d;
        }

        public ShardInfo getShardInfo() {
            return shardInfo;
        }

        public void setShardInfo(ShardInfo shardInfo) {
            this.shardInfo = shardInfo;
        }

        public int getCountLeft() {
            return countLeft;
        }

        public void setCountLeft(int countLeft) {
            this.countLeft = countLeft;
        }

        public int getCountEq() {
            return countEq;
        }

        public void setCountEq(int countEq) {
            this.countEq = countEq;
        }

        public int getCountLeftEq() {
            return countLeftEq;
        }

        public void setCountLeftEq(int countLeftEq) {
            this.countLeftEq = countLeftEq;
        }
    }
}
